#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>

int flag = 0;
void handle (int sig)
{
    printf ("thread[ %ld ] recv signal\n", pthread_self ());
    flag = 1;
}
void *fun1 (void *arg)
{
    signal (SIGINT, handle);
    while (1)
    {
	printf ("thread 1 [%ld]	\n", pthread_self ());
	sleep (2);
    }
    return 0;
}
void *fun2 (void *arg)
{
    while (flag == 0)
    {
	printf ("thread 2 [%ld] \n", pthread_self ());
	sleep (2);
    }
    return 0;
}
int main ()
{
    printf ("main [%ld]\n", pthread_self ());
    pthread_t p1,p2;
    pthread_create (&p1, 0, fun1, 0);
    pthread_create (&p2, 0, fun2, 0);
    sleep (5);
    pthread_kill (p2, SIGINT);
    pthread_join (p1, 0);
    pthread_join (p2, 0);
    printf ("exit\n");
    return 0;
}
